package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.vo.SjExecutionHistoryVO;
import com.ruoyi.system.domain.vo.SjHistoryDoubtDistributionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SjExecutionHistoryMapper;
import com.ruoyi.system.domain.SjExecutionHistory;
import com.ruoyi.system.service.ISjExecutionHistoryService;

/**
 * 历史记录Service业务层处理
 * 
 * @author zrr
 * @date 2024-11-06
 */
@Service
public class SjExecutionHistoryServiceImpl implements ISjExecutionHistoryService
{
    @Autowired
    private SjExecutionHistoryMapper sjExecutionHistoryMapper;

    /**
     * 查询历史记录
     * 
     * @param id 历史记录主键
     * @return 历史记录
     */
    @Override
    public SjExecutionHistory selectSjExecutionHistoryById(Integer id)
    {
        return sjExecutionHistoryMapper.selectSjExecutionHistoryById(id);
    }

    /**
     * 查询历史记录列表
     * 
     * @param sjExecutionHistory 历史记录
     * @return 历史记录
     */
    @Override
    public List<SjExecutionHistory> selectSjExecutionHistoryList(SjExecutionHistory sjExecutionHistory)
    {
        return sjExecutionHistoryMapper.selectSjExecutionHistoryList(sjExecutionHistory);
    }

    /**
     * 新增历史记录
     * 
     * @param sjExecutionHistory 历史记录
     * @return 结果
     */
    @Override
    public int insertSjExecutionHistory(SjExecutionHistory sjExecutionHistory)
    {
        sjExecutionHistory.setCreateTime(DateUtils.getNowDate());
        return sjExecutionHistoryMapper.insertSjExecutionHistory(sjExecutionHistory);
    }

    /**
     * 修改历史记录
     * 
     * @param sjExecutionHistory 历史记录
     * @return 结果
     */
    @Override
    public int updateSjExecutionHistory(SjExecutionHistory sjExecutionHistory)
    {
        sjExecutionHistory.setUpdateTime(DateUtils.getNowDate());
        return sjExecutionHistoryMapper.updateSjExecutionHistory(sjExecutionHistory);
    }

    /**
     * 批量删除历史记录
     * 
     * @param ids 需要删除的历史记录主键
     * @return 结果
     */
    @Override
    public int deleteSjExecutionHistoryByIds(Integer[] ids)
    {
        return sjExecutionHistoryMapper.deleteSjExecutionHistoryByIds(ids);
    }

    /**
     * 删除历史记录信息
     * 
     * @param id 历史记录主键
     * @return 结果
     */
    @Override
    public int deleteSjExecutionHistoryById(Integer id)
    {
        return sjExecutionHistoryMapper.deleteSjExecutionHistoryById(id);
    }

    /**
     * 查询执行历史数量
     * @return
     */
    @Override
    public SjExecutionHistoryVO selectSjExecutionHistoryCount() {
        Integer success = sjExecutionHistoryMapper.selectSuccessHistoryCount();
        Integer fails = sjExecutionHistoryMapper.selectFailsHistoryCount();
        Integer count = sjExecutionHistoryMapper.selectHistoryCount();
        SjExecutionHistoryVO sjExecutionHistoryVO =
                new SjExecutionHistoryVO(success, fails, count);
        return sjExecutionHistoryVO;
    }

    /**
     * 疑点分布查询
     * @return
     */
    @Override
    public List<SjHistoryDoubtDistributionVO> selectDistribution() {
        List<SjHistoryDoubtDistributionVO> orderCount =
                sjExecutionHistoryMapper.selectOrderCount();
        for (SjHistoryDoubtDistributionVO sjHistoryDoubtDistributionVO : orderCount) {
            sjHistoryDoubtDistributionVO.setQuestionCount(sjHistoryDoubtDistributionVO.getOrderCount());
        }
        return orderCount;
    }

}
